Skip to main content

libobs_simple\sources\linux\sources/
alsa_input.rs

1use libobs_wrapper::sources::ObsSourceRef;
2
3use crate::sources::macro_helper::{define_object_manager, impl_default_builder};
4
5define_object_manager!(
6    #[derive(Debug)]
7    /// A source for ALSA (Advanced Linux Sound Architecture) audio input.
8    ///
9    /// This source captures audio from ALSA-compatible devices on Linux systems.
10    /// It provides low-level access to audio hardware through the ALSA subsystem.
11    struct AlsaInputSource("alsa_input_capture", *mut libobs::obs_source) for ObsSourceRef {
12        /// ALSA device ID (e.g., "default", "hw:0,0", or custom PCM device)
13        #[obs_property(type_t = "string")]
14        device_id: String,
15
16        /// Custom PCM device name (used when device_id is "__custom__")
17        #[obs_property(type_t = "string")]
18        custom_pcm: String,
19
20        /// Audio sample rate in Hz (e.g., 44100, 48000)
21        #[obs_property(type_t = "int")]
22        rate: i64,
23    }
24);
25
26impl AlsaInputSourceBuilder {
27    /// Set a custom PCM device
28    pub fn set_custom_device(self, pcm_device: &str) -> Self {
29        self.set_device_id("__custom__").set_custom_pcm(pcm_device)
30    }
31
32    /// Set a standard ALSA device
33    pub fn set_alsa_device(self, device: &str) -> Self {
34        self.set_device_id(device)
35    }
36}
37
38impl_default_builder!(AlsaInputSourceBuilder);